package com.sangananitsolution.database;

import com.sangananitsolution.database.DatabaseTables.FavouitreItem;
import com.sangananitsolution.database.DatabaseTables.UserInfo;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DatabaseHelper extends SQLiteOpenHelper {

	public static final String DATABASE_NAME = "GarageSalesGoGo.db";
	public static final int DATABASE_VERSION = 2;

	// ------GarageSalesGoGo CREATE AND DROP STATEMENTS------

	public DatabaseHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);

	}

	private static final String CREATE_TABLE_USERINFO = " CREATE TABLE "
			+ UserInfo.TABLE_NAME + "(" + UserInfo.UID
			+ " INTEGER PRIMARY KEY AUTOINCREMENT ," + UserInfo.FIRST_NAME
			+ " TEXT ," + UserInfo.LAST_NAME + " TEXT ," + UserInfo.EMAIL
			+ " TEXT," + UserInfo.PHONE + " INTEGER," + UserInfo.Country
			+ " TEXT ," + UserInfo.FacebookId + " TEXT ," + UserInfo.HashCode
			+ " TEXT , " + UserInfo.IsValidUser + " TEXT ," + UserInfo.Latitude
			+ " INTEGER ," + UserInfo.Longitude + " INTEGER ,"
			+ UserInfo.StatusMessage + " TEXT ," + UserInfo.UserId
			+ " INTEGER ," + UserInfo.UserImage + " TEXT);";

	private static final String DROP_TABLE_USERINFO = " DROP TABLE  IF EXISTS "
			+ UserInfo.TABLE_NAME;

	private static final String CREATE_TABLE_AddtoFavouirte = " CREATE TABLE "
			+ FavouitreItem.TABLE_NAME + " (" + FavouitreItem.ProductImages
			+ " VARCHAR, " + FavouitreItem.GarageSaleTitle + " VARCHAR, "
			+ FavouitreItem.StartDate + " VARCHAR, "
			+ FavouitreItem.OneOrTwoDaySale + " VARCHAR, "
			+ FavouitreItem.SaleStartTime + " VARCHAR, "
			+ FavouitreItem.SaleFinishTime + " VARCHAR, "
			+ FavouitreItem.UnitStreeNo + " VARCHAR, "
			+ FavouitreItem.StreeName + " VARCHAR, " + FavouitreItem.Suburb
			+ " VARCHAR, " + FavouitreItem.City + " VARCHAR, "
			+ FavouitreItem.State + " VARCHAR, " + FavouitreItem.PostCode
			+ " VARCHAR, " + FavouitreItem.Description + " VARCHAR, "
			+ FavouitreItem.EarlyBirdMessage + " VARCHAR, "
			+ FavouitreItem.BadWeatherMessage + " VARCHAR, "
			+ FavouitreItem.GoodsType + " VARCHAR, "
			+ FavouitreItem.CurrentUser + " VARCHAR, "
			+ FavouitreItem.Longitude + " VARCHAR, " + FavouitreItem.Latitude
			+ " VARCHAR, " + FavouitreItem.ProductID + " VARCHAR);";
	
	private static final String DROP_TABLE_AddtoFavouirte = " DROP TABLE  IF EXISTS "
			+ FavouitreItem.TABLE_NAME;

	@Override
	public void onCreate(SQLiteDatabase db) {
	
		db.execSQL(CREATE_TABLE_USERINFO);
		db.execSQL(CREATE_TABLE_AddtoFavouirte);

	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		
		db.execSQL(DROP_TABLE_USERINFO);
		db.execSQL(DROP_TABLE_AddtoFavouirte);

	}

}
